// 饿汉模式
//class Singleton{
//     private static Singleton instance = new Singleton();
//     public static Singleton getInstance(){
//         return instance ;
//     }
//     private Singleton(){
//     }
//
//}

// 懒汉模式
class Singleton{
    private static volatile Singleton instance = null ;
     public static Singleton getInstance(){
         if(instance == null){
             synchronized(Singleton.class){
                 if(instance == null){
                     instance = new Singleton();
                 }
             }
         }
         return instance;
     }
     private Singleton(){
     }
}

public class Test1 {
    static Singleton s1 = null ;
    static Singleton s2 = null ;

    public static void main(String[] args) {

        Thread t1 = new Thread(()-> {
            s1 = Singleton.getInstance();
        });
        Thread t2 = new Thread(()-> {
            s2 = Singleton.getInstance();
        });
        t1.start();
        t2.start();
        System.out.println(s1 == s2);
    }
}
